package cn.wolfcode.crm.query;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;

@Getter@Setter
public class AccidentChartQueryObject {
    private String agencyName;
    private String productName;
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GTM+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date beginDate;
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GTM+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date endDate;
    private String groupByType;
    //使用map结合封装分组的类型
    //分组类型只需要初始化一次就行了 //GROUP BY saleman.name/p.name/c.name/p.brand_name/sa.vdate
    public static Map<String,String> groupByTypes = new LinkedHashMap<>();
    static {
        groupByTypes.put("e.username","保险人员");
        groupByTypes.put("a.name","保险机构");
        groupByTypes.put("p.name","险种");
        groupByTypes.put("DATE_FORMAT(s.purchasedate,'%Y-%m')","保单日期(月)");
        groupByTypes.put("DATE_FORMAT(s.purchasedate,'%Y-%m-%d')","保单日期(日)");
    }

    public String getGroupByType(){
        if(groupByType==null || groupByType.trim().length()==0){
            return "e.username";
        }
        return groupByType;
    }

}
